#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>

int main()
{
  printf("hello printf\n");
  fprintf(stdout, "hello fprintf\n");
  fputs("hello fputs\n", stdout);
  
  const char* msg = "hello write\n";
  write(1, msg, strlen(msg));

  fork();







//  umask(0);
//  int fd = open("tmp.txt", O_WRONLY | O_CREAT | O_RDONLY, 0666);
//  dup2(fd, 1); 
//  
//  printf("hello printf\n");
//  fprintf(stdout, "hello fprintf\n");
//  fputs("hello fputs\n", stdout);
//  char* msg = "hello write\n";
//  write(fd, msg, strlen(msg));
//  
//  fflush(stdout);
//  close(fd);
  
  
  
  
  //close(1);
  //umask(0);
  //int fd = open("tmp.txt", O_WRONLY | O_CREAT | O_RDONLY, 0666);

  //if(fd < 0){
  //  perror("open");
  //  return 2;
  //}
 

  //printf("hello printf\n");
  //fprintf(stdout, "hello fprintf\n");
  //fputs("hello fputs\n", stdout); 

  //char* msg = "hello wirte\n";
  //write(fd, msg, strlen(msg));

  //fflush(stdout);
  //close(fd);











//  int fd1 = open("tmp.txt", O_WRONLY | O_CREAT, 0666);
//k  printf("fd1:%d\n", fd1);
//k  int fd2 = open("tmp.txt", O_WRONLY | O_CREAT, 0666);
//k  printf("fd2:%d\n", fd2);
//k  int fd3 = open("tmp.txt", O_WRONLY | O_CREAT, 0666);
//k  printf("fd3:%d\n", fd3);
//k  int fd4 = open("tmp.txt", O_WRONLY | O_CREAT, 0666);
//k  printf("fd4:%d\n", fd4);
//k  close(4);
//k  int fd5 = open("tmp.txt", O_WRONLY | O_CREAT, 0666);
//k  printf("close 4-->fd5:%d\n", fd5);
//k  int fd6 = open("tmp.txt", O_WRONLY | O_CREAT, 0666);
//k  printf("fd6:%d\n", fd6);
//k  int fd7 = open("tmp.txt", O_WRONLY | O_CREAT, 0666);
//k  printf("fd7:%d\n", fd7);
//k  int fd8 = open("tmp.txt", O_WRONLY | O_CREAT, 0666);
//k  printf("fd8:%d\n", fd8);




















//  umask(0);
//  close(1);
//  int fd = open("tmp.txt", O_WRONLY | O_CREAT, 0666);
//  if(fd < 0) {
//    perror("open");
//    return 1;
//  }
//
//  char* msg = "hello write\n";
//  write(fd, msg, strlen(msg)); 
//
//  printf("hello printf\n");
//  fprintf(stdout, "hello fprintf\n");
//  
//  fflush(stdout);
//
//  close(fd);
  //close(1);






  //close(1);
  //FILE* pf = fopen("tmp.txt", "a+");

  //fputs("hello fputs!\n", pf);

  //printf("hello printf!\n");
  //fprintf(stdout, "hello fprintf!\n");

  //char* msg = "hello write!\n";
  //write(1, msg, strlen(msg));

  ////fflush(stdout);
  ////rewind(pf);
  //fseek(pf, 0, SEEK_SET);
  //char ch;
  //while((ch = fgetc(pf)) != EOF){
  //  printf("%c", ch);
  //}


  //fflush(stdout);
  //fclose(pf);
  return 0;
}
